import { Column, Entity } from "typeorm";

import { BaseEntity } from "@/entities/base.entity";
import { ApiProperty } from "@nestjs/swagger";
import { Transform } from "class-transformer";
import { Enabled } from "@/common/enums/enabled.enum";
import { Deleted } from "@/common/enums/deleted.enum";

// eslint-disable-next-line @typescript-eslint/no-var-requires
const moment = require("moment");

@Entity("auth_tenants")
export class TenantEntity extends BaseEntity {
  @ApiProperty({ description: "租户编码" })
  @Column({ type: "varchar", name: "tenant_code" })
  tenantCode: string;

  @ApiProperty({ description: "租户名称" })
  @Column({ type: "varchar", name: "tenant_name" })
  tenantName: string;

  @ApiProperty({ description: "过期时间" })
  @Column({ type: "datetime" })
  expire: Date;

  @ApiProperty({ description: "数据服务器地址" })
  @Column({ type: "varchar", name: "db_host" })
  dbHost: string;

  @ApiProperty({ description: "数据库端口号" })
  @Column({ type: "int", name: "db_port" })
  dbPort: number;

  @ApiProperty({ description: "数据库名称" })
  @Column({ type: "varchar", name: "db_name" })
  dbName: string;

  @ApiProperty({ description: "数据库账号" })
  @Column({ type: "varchar", name: "db_username" })
  dbUsername: string;

  @ApiProperty({ description: "数据库密码" })
  @Column({ type: "varchar", name: "db_password" })
  dbPassword: string;

  @ApiProperty({ description: "余额" })
  @Column({ type: "decimal" })
  balance: number;

  @ApiProperty({ description: "手机号" })
  @Column({ type: "varchar" })
  phone: string;

  @ApiProperty({ description: "联系人" })
  @Column({ type: "varchar" })
  contacts: string;

  @ApiProperty({ description: "删除" })
  @Column({ type: "int", default: 0 })
  deleted: Deleted;

  @ApiProperty({ description: "启用" })
  @Column({ type: "int", default: 1 })
  enabled: Enabled;

  @ApiProperty({ description: "创建时间" })
  @Transform((createTime: any) => {
    console.log("createTime", createTime);

    return moment(createTime.value).format("YYYY-MM-DD HH:mm:ss");
  })
  @Column({ type: "datetime", name: "create_time" })
  createTime: Date;

  @ApiProperty({ description: "备注" })
  @Column({ type: "varchar" })
  remark: string;
}
